package cn.hackcloud.annotation.test;

import org.junit.Test;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;

import cn.hackcloud.annotation.bean.Boss;
import cn.hackcloud.annotation.config.MainConfigOfAutowired;
import cn.hackcloud.annotation.dao.BookDao;
import cn.hackcloud.annotation.service.BookService;

public class IOCTestAutowired {
	AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(MainConfigOfAutowired.class);

	@Test
	public void test() {
		System.out.println("容器创建完成...");
		BookService bookService = ctx.getBean(BookService.class);
		bookService.print();
		BookDao bookDao = ctx.getBean(BookDao.class);
		System.out.println(bookDao);
		Boss boss = ctx.getBean(Boss.class);
		System.out.println(boss);
		// printBeans(ctx);

	}

	public void printBeans(AnnotationConfigApplicationContext context) {
		String[] beans = context.getBeanDefinitionNames();
		for (String bean : beans) {
			System.out.println(bean);
		}
	}

}
